package com.dhcc.bpm.modules.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.api.entity.IssueApi;
import com.dhcc.bpm.modules.api.service.IIssueApiService;
import com.dhcc.bpm.modules.api.vo.IssueApiVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @ClassName IssueApiController
 * @Description api发布表 控制器
 * @Author daina
 * @Date 2020/2/25 13:14
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-issue/issueapi")
@Api(value = "api发布表", tags = "api发布表接口")
public class IssueApiController extends BladeController {

	private IIssueApiService issueApiService;

	/**
	 * @Description api发布表详情
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param issueApi
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.api.entity.IssueApi>
	 **/
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "api发布表详情", notes = "传入issueApi")
	@Log(title = "api发布表详情", businessType = BusinessType.SELECT)
	@ApiLog("api发布表详情")
	public R<IssueApi> detail(IssueApi issueApi) {
		IssueApi detail = issueApiService.getOne(Condition.getQueryWrapper(issueApi));
		return R.data(detail);
	}

	/**
	 * @Description 分页 api发布表
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param issueApi
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.api.entity.IssueApi>>
	 **/
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "api发布表分页", notes = "传入issueApi")
	@Log(title = "api发布表分页", businessType = BusinessType.SELECT)
	@ApiLog("api发布表分页")
	public R<IPage<IssueApi>> list(IssueApi issueApi, Query query) {
		IPage<IssueApi> pages = issueApiService.page(Condition.getPage(query), Condition.getQueryWrapper(issueApi));
		return R.data(pages);
	}

	/**
	 * @Description  自定义分页 api发布表
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param issueApi
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.api.vo.IssueApiVO>>
	 **/
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入issueApi")
	@Log(title = "api发布表分页", businessType = BusinessType.SELECT)
	@ApiLog("api发布表分页")
	public R<IPage<IssueApiVO>> page(IssueApiVO issueApi, Query query) {
		IPage<IssueApiVO> pages = issueApiService.selectIssueApiPage(Condition.getPage(query), issueApi);
		return R.data(pages);
	}

	/**
	 * @Description 新增 api发布表
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param issueApi
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增api发布信息", notes = "传入issueApi")
	@Log(title = "新增api发布信息", businessType = BusinessType.INSERT)
	@ApiLog("新增api发布信息")
	public R save(@Valid @RequestBody IssueApi issueApi) {
		return R.status(issueApiService.save(issueApi));
	}

	/**
	 * @Description 修改 api发布表
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param issueApi
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改api发布表", notes = "传入issueApi")
	@Log(title = "修改api发布表", businessType = BusinessType.UPDATE)
	@ApiLog("修改api发布表")
	public R update(@Valid @RequestBody IssueApi issueApi) {
		return R.status(issueApiService.updateById(issueApi));
	}

	/**
	 * @Description 新增或修改 api发布表
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param issueApi
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改api发布表", notes = "传入issueApi")
	@Log(title = "新增或修改api发布表", businessType = BusinessType.INSERT)
	@ApiLog("新增或修改api发布表")
	public R submit(@Valid @RequestBody IssueApi issueApi) {
		return R.status(issueApiService.saveOrUpdate(issueApi));
	}

	
	/**
	 * @Description  删除 api发布表
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "删除 api发布表", notes = "传入ids")
	@Log(title = "删除 api发布表", businessType = BusinessType.DELETE)
	@ApiLog("删除 api发布表")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(issueApiService.deleteLogic(Func.toLongList(ids)));
	}

	/**
	 * @Description 查询issue_api
	 * @Author daina
	 * @Date 14:45 2020/2/25
	 * @param id
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/listIssueApis")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "查询issue_api", notes = "传入id")
	@Log(title = "查询issue_api", businessType = BusinessType.SELECT)
	@ApiLog("查询issue_api")
	public R listIssueApis(@RequestParam Long id) {
		List<com.dhcc.bpm.modules.api.entity.Api> issueApis = issueApiService.selectApisById(id);
		R r = new R();
		r.setData(issueApis);
		r.setSuccess(true);
		return r;
	}
	
}
